package com.echo.week02.jvm;

import java.util.concurrent.TimeUnit;

/**
 * @Author echo
 * @Description
 * 思考题：如果创建海量线程线程的时候，同时每个线程疯狂递归，请问到底是先OOM还是StackOverflowError？
 * 先出现了 StackOverflowError
 * @Date 2023/9/25.
 * @Version 1.0
 */
public class TestThread {
    public static void main(String[] args) {
        for (int i=0;i<100000;i++){
            new Thread("Thread-"+i){
                @Override
                public void run() {
                    String name = Thread.currentThread().getName();
                    System.out.println(name);
                    recurive(30000);
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println();
                }
            }.start();;
        }
    }
    public static void recurive(double d){
        if (d==0){
            return;
        }
        recurive(d-1);
    }
}
